Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add instance.getValue() and instance.setValue(newVal) #88

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

amlan-sw
Copy link

@amlan-sw amlan-sw commented Aug 5, 2024

instance.setValue(newVal)

//-- regular select
newVal = 'foo';

//-- selected foo and bar option for multiple
newVal = ['foo','bar']; 

source SELECT tag will also change its value and highlight following newVal

currentVal = instance.getValue()

  • currentVal is string if not multiple select
  • currentVal is Array like ['foo','bar'] or ['boo'] for multiple select

Summary by Sourcery

Add methods to set and get the value of the select element, enhancing the functionality to support both single and multiple selections.

New Features:

  • Introduce instance.setValue(newVal) method to set the value of the select element, supporting both single and multiple selections.
  • Introduce instance.getValue() method to retrieve the current value of the select element, returning a string for single selections and an array for multiple selections.

//-- regular select
newVal = 'foo';

//-- selected foo and bar option for multiple
newVal = ['foo','bar']; 

currentVal = getValue()
//-- currentVal is Array like ['foo','bar'] or ['boo'] for multiple select
//-- currentVal is string if not multiple
Copy link

sourcery-ai bot commented Aug 5, 2024

Reviewer's Guide by Sourcery

This pull request introduces two new methods, setValue and getValue, to the NiceSelect class. The setValue method allows for programmatically setting the value of the select element, while the getValue method retrieves the current value. Additionally, the handling of selected options has been improved in the _onItemClicked and resetSelectValue methods to ensure more robust manipulation of the 'selected' attribute.

File-Level Changes

Files Changes
src/js/nice-select2.js Enhanced the NiceSelect class with new methods for setting and getting the value of the select element, and improved the handling of selected options.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @amlan-sw - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using opt.selected = false instead of delete(opt.selected) for better readability and consistency with common JavaScript practices.
  • The setValue() method is quite complex, especially for handling multiple selects. Consider refactoring it into smaller, more focused functions to improve readability and maintainability.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

src/js/nice-select2.js Outdated Show resolved Hide resolved
src/js/nice-select2.js Outdated Show resolved Hide resolved
amlan-sw and others added 2 commits August 5, 2024 22:43
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant